package com.situ.day5.cal;

import org.junit.Test;

public class CalDemo {

    @Test
    public void test1() {
        Add add = new Add();
        add.setNum1(3);
        add.setNum2(5);
        System.out.println(add.getResult());

        Add add1 = new Add(4, 6);
        System.out.println(add1.getResult());
    }

    @Test
    public void test2() {
        //如果子类重写了getResult(),调用的是子类的getResult(),
        //如果子类没有重写调用父类getResult()
        Add add = new Add(3, 2);
        int result = add.getResult();

        //声明成父类类型，new子类对象
        //如果子类重写了getResult(),调用的是子类的getResult(),
        //如果子类没有重写调用父类getResult()
        AbstractCal cal = new Add(3, 2);
        System.out.println(cal.getResult());
        cal = new Sub(3, 2);
        System.out.println(cal.getResult());

        //Student继承Person 学生就是人
        //Person p = new Student();
        //p = new Teacher();
    }

    public void cal(Add c) {
        c.getResult();
    }

    public void cal(Sub c) {
        c.getResult();
    }

    //面向接口(抽象)编程
    public void cal(AbstractCal cal) {
        cal.getResult();
    }
}
